package com.xydtech.ecard.config.controller;

import com.xydtech.common.annotation.Log;
import com.xydtech.common.core.controller.BaseController;
import com.xydtech.common.core.domain.AjaxResult;
import com.xydtech.common.core.page.TableDataInfo;
import com.xydtech.common.enums.BusinessType;
import com.xydtech.common.utils.poi.ExcelUtil;
import com.xydtech.ecard.config.domain.EcardBusiConfigList;
import com.xydtech.ecard.config.service.IEcardBusiConfigListService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 电子名片业务填报类型配置积分明细Controller
 *
 * @author yuzhiguo
 * @date 2024-09-27 下午1:26
 */
@Controller
@RequestMapping("/ecard/config/busiConfigList")
public class EcardBusiConfigListController extends BaseController
{
    private String prefix = "ecard/config/busiConfigList";

    @Autowired
    private IEcardBusiConfigListService ecardBusiConfigListService;

    @RequiresPermissions("ecard:config:busiConfigList:view")
    @GetMapping("/{configId}/{busiType}/{busiCode}")
    public String busiConfigList(@PathVariable("configId") Long configId,
                                 @PathVariable("busiType") String busiType,
                                 @PathVariable("busiCode") String busiCode,
                                 ModelMap mmap)
    {
        mmap.put("configId", configId);
        mmap.put("busiType", busiType);
        mmap.put("busiCode", busiCode);
        return prefix + "/busiConfigList";
    }

    /**
     * 查询电子名片业务填报类型配置积分明细列表
     */
    @RequiresPermissions("ecard:config:busiConfigList:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(EcardBusiConfigList ecardBusiConfigList)
    {
        startPage();
        List<EcardBusiConfigList> list = ecardBusiConfigListService.selectEcardBusiConfigListList(ecardBusiConfigList);
        return getDataTable(list);
    }

    /**
     * 导出电子名片业务填报类型配置积分明细列表
     */
    @RequiresPermissions("ecard:config:busiConfigList:export")
    @Log(title = "电子名片业务填报类型配置积分明细", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(EcardBusiConfigList ecardBusiConfigList)
    {
        List<EcardBusiConfigList> list = ecardBusiConfigListService.selectEcardBusiConfigListList(ecardBusiConfigList);
        ExcelUtil<EcardBusiConfigList> util = new ExcelUtil<EcardBusiConfigList>(EcardBusiConfigList.class);
        return util.exportExcel(list, "电子名片业务填报类型配置积分明细数据");
    }

    /**
     * 新增电子名片业务填报类型配置积分明细
     */
    @GetMapping("/add/{configId}/{busiType}/{busiCode}")
    public String add(@PathVariable("configId") Long configId,
                      @PathVariable("busiType") String busiType,
                      @PathVariable("busiCode") String busiCode,
                      ModelMap mmap)
    {
        mmap.put("configId", configId);
        mmap.put("busiType", busiType);
        mmap.put("busiCode", busiCode);
        return prefix + "/add";
    }

    /**
     * 新增保存电子名片业务填报类型配置积分明细
     */
    @RequiresPermissions("ecard:config:busiConfigList:add")
    @Log(title = "电子名片业务填报类型配置积分明细", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(EcardBusiConfigList ecardBusiConfigList)
    {
        return toAjax(ecardBusiConfigListService.insertEcardBusiConfigList(ecardBusiConfigList));
    }

    /**
     * 修改电子名片业务填报类型配置积分明细
     */
    @GetMapping("/edit/{id}/{configId}/{busiType}/{busiCode}")
    public String edit(@PathVariable("id") Long id,
                       @PathVariable("configId") Long configId,
                       @PathVariable("busiType") String busiType,
                       @PathVariable("busiCode") String busiCode,
                       ModelMap mmap)
    {
        EcardBusiConfigList ecardBusiConfigList = ecardBusiConfigListService.selectEcardBusiConfigListById(id);
        mmap.put("ecardBusiConfigList", ecardBusiConfigList);
        mmap.put("configId", configId);
        mmap.put("busiType", busiType);
        mmap.put("busiCode", busiCode);
        return prefix + "/edit";
    }

    /**
     * 修改保存电子名片业务填报类型配置积分明细
     */
    @RequiresPermissions("ecard:config:busiConfigList:edit")
    @Log(title = "电子名片业务填报类型配置积分明细", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(EcardBusiConfigList ecardBusiConfigList)
    {
        return toAjax(ecardBusiConfigListService.updateEcardBusiConfigList(ecardBusiConfigList));
    }

    /**
     * 删除电子名片业务填报类型配置积分明细
     */
    @RequiresPermissions("ecard:config:busiConfigList:remove")
    @Log(title = "电子名片业务填报类型配置积分明细", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(ecardBusiConfigListService.deleteEcardBusiConfigListByIds(ids));
    }
}
